package codetop.microsoft.T152;

/**
 * @Author: 18362
 * @Create: 2022-08-14 10:56:01 星期日
 */
class Solution {
    public int maxProduct(int[] nums) {
        int[] min = new int[nums.length], max = new int[nums.length];
        min[0] = nums[0];
        max[0] = nums[0];
        int maxProd = max[0];
        for (int i=1; i<nums.length; ++i) {
            int a = nums[i]*min[i-1], b = nums[i]*max[i-1];
            min[i] = Math.min(nums[i], Math.min(a, b));
            max[i] = Math.max(nums[i], Math.max(a, b));
            maxProd = Math.max(maxProd, max[i]);
        }
        return maxProd;
    }
}